import pygame, random, sys
from pygame.locals import *

import classes
import functions

class mastercontrol:
	def __init__(self, screen, scalegfx):
		self.screen = screen
		self.scalegfx = scalegfx
		self.interactiveIcons = []

		self.MainBackgroundImageDict = functions.scaled_image_dict('mainimage', '', '', 'gfx/Main.png', self.scalegfx, 0, 0)

		self.MessagesIdleDict = functions.scaled_image_dict('mainimage', '', '', 'gfx/MessagesIdleBlitStrip.png', self.scalegfx, 0, 0)
		self.MessagesDict = functions.scaled_image_dict('mainimage', '', '', 'gfx/MessagesBlitStrip.png', self.scalegfx, 0, 0)
		self.MessagesIdleIconAnimate = classes.animate_this(self.screen, self.MessagesIdleDict['surface'], (self.MessagesIdleDict['rect'].width / 8), self.MessagesIdleDict['rect'].height, (24*self.scalegfx), (59*self.scalegfx), 200)
		self.MessagesIconAnimate = classes.animate_this(self.screen, self.MessagesDict['surface'], (self.MessagesDict['rect'].width / 8), self.MessagesDict['rect'].height, (24*self.scalegfx), (59*self.scalegfx), 80)

		self.EarthIconDict = functions.scaled_image_dict('earthicon', '', '', 'gfx/earth_city_ico_blit_strip.png', self.scalegfx, 0, 0)
		self.EarthIconAnimate = classes.animate_this(self.screen, self.EarthIconDict['surface'], (self.EarthIconDict['rect'].width / 8), self.EarthIconDict['rect'].height, 1, 152, 100)

		self.DiskIconDict = functions.scaled_image_dict('mainmenu', 'Main Menu', 'screen', 'gfx/diskaccess.png', self.scalegfx, 1, 56)
		self.DiskBlitStrip = functions.scaled_image_dict('', '', '', 'gfx/DiskBlitStrip.png', self.scalegfx, 0, 0)
		self.DiskAnimate = classes.animate_this(self.screen, self.DiskBlitStrip['surface'], (self.DiskBlitStrip['rect'].width / 8), self.DiskBlitStrip['rect'].height, (1*self.scalegfx), (56*self.scalegfx), 120)

		self.EarthIconDict = functions.scaled_image_dict('earthcity', 'Earth City', 'screen', 'gfx/earth_city_ico.png', self.scalegfx, 1, 75)
		self.TickerDict = functions.scaled_image_dict('ticker', 'Advance Time', 'tick', 'gfx/ticker.png', self.scalegfx, 52, 224)

	def regenerateInteractiveIcons(self):
		del self.interactiveIcons [:]
		self.interactiveIcons.append(self.DiskIconDict)
		self.interactiveIcons.append(self.EarthIconDict)
		self.interactiveIcons.append(self.TickerDict)

	def display(self, currentscreen, timepassed, player):
		self.regenerateInteractiveIcons()
		self.screen.blit(self.MainBackgroundImageDict['surface'], self.MainBackgroundImageDict['rect'])
		self.DiskAnimate.stop()
		if (player.unreadMsgs()):
			self.MessagesIconAnimate.update(timepassed)
		else:
			self.MessagesIdleIconAnimate.update(timepassed)
		if (currentscreen == 'earthcity'):
			self.EarthIconAnimate.update(timepassed)
		else:
			self.EarthIconAnimate.stop()
		if (currentscreen == 'mainmenu'):
			self.DiskAnimate.update(timepassed)
		else:
			self.DiskAnimate.reset()
			self.DiskAnimate.stop()
		self.screen.blit(self.TickerDict['surface'], self.TickerDict['rect'])

	def mainmenu(self):
		self.regenerateInteractiveIcons()

	def displaysolarcontrol(self,solsystem):
		self.solsystem = solsystem

	def myicons(self):
		return(self.interactiveIcons)
